﻿#include "frienditem.h"
#include "ui_frienditem.h"

FriendItem::FriendItem(QString email,QString username,QString sign,QWidget *parent) :
    QWidget(parent)
    , ui(new Ui::FriendItem)
    , email(email)
{
    ui->setupUi(this);
    ui->name_LB->setText(username);
    ui->tab_LB->setText(sign);
    updateHeadImg();
}

FriendItem::~FriendItem()
{
    delete ui;
}
void FriendItem::updateHeadImg(){
    if(QFile::exists(QString("./accountData/Res/%1/headImg/head.png").arg(email))){
        ui->img_LB->setStyleSheet(QString("\
            #img_LB{\
                border-radius:25px;\
                border-image:url('./accountData/Res/%1/headImg/head.png') 0 0 0 0 stretch stretch;\
            }\
        ").arg(email));
    }
}
void FriendItem::setNormalStyle(){
    ui->FriendItem_content->setStyleSheet(R"(
        #FriendItem_content:hover{
            background-color:rgb(242, 242, 242);
        }
    )");
}
void FriendItem::setClickStyle(){
    ui->FriendItem_content->setStyleSheet(R"(
        #FriendItem_content{
            background-color:rgb(235, 235, 235);
        }
    )");
}
void FriendItem::mousePressEvent(QMouseEvent* event){
    if(event->button()==Qt::LeftButton)
    {
        emit clicked(this);
    }
}
void FriendItem::mouseDoubleClickEvent(QMouseEvent* event){
    if(event->button()==Qt::LeftButton){
        emit showComm(email,ui->name_LB->text());
    }
}
QString FriendItem::getEmail(){
    return this->email;
}

